package cn.tede.file;

import java.io.*;

/*练习字节输入流*/
public class TestIn {
    public static void main(String[] args)  {
        method1();//普通字节输入流
        //method2();//高效字节输入流
    }

    private static void method2() {
    }

    private static void method1() {

        InputStream in2=null;
        try {
            //InputStream in=new InputStream();
            //InputStream in=new FileInputStream(new File("D:\\ready\\1.txt"));
            in2=new FileInputStream("D:\\ready\\1.txt");

            /*System.out.println(in2.read());
            System.out.println(in2.read());
            System.out.println(in2.read());
            System.out.println(in2.read());
            System.out.println(in2.read());*/

            int b;
            while ((b = in2.read())!=-1){
                System.out.println(b);
            }


        } catch (Exception e) {
            e.printStackTrace();//打印错误轨迹,给程序员,方便调错
            /*finally{}是tre-catch结构在的第三个部分
            * 这部分无论是否捕获到异常,是一定会被执行到的代码块,常用于关流*/
        }finally {
            try {
                in2.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
